package com.bj58.migrate.task;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.bj58.migrate.ConditionBuilder;
import com.bj58.migrate.condition.CycleCondtion;
import com.bj58.migrate.condition.impl.CateCondition;
import com.bj58.migrate.condition.impl.LocalCondition;
import com.bj58.migrate.condition.impl.PostdateCondition;
import com.bj58.migrate.condition.impl.StateCondition;
import com.bj58.migrate.helper.DateHelper;
import com.bj58.zhaopin.app.engine.context.AppContext;
import com.bj58.zhaopin.app.engine.task.QuartzTask;

public class TaskTest extends QuartzTask{

	// static{
	// com.bj58.spat.scf.client.SCFInit.init( "/opt/apps/app/avgsalary/conf/scf.config" );
	// }

	private static ConditionBuilder builder;

	/**
	 * @param args
	 */
	public static void main( String[] args ){

		com.bj58.spat.scf.client.SCFInit.init( ConditionBuilder.DEFAULT_PATH + "/conf/scf.config" );

		System.out.println( "定时任务" );
		String[] newargs = { "sr", "avg", "201507" };

		Task task = new Task( newargs );
		task.run( newargs );
	}

	public void test(){

		String formatFileName = DateHelper.convertDatetoString( "yyyyMM", new Date() );
		String[] args = { "sr", "avg", formatFileName };

		Task task = new Task( args );
		task.run( args );
	}

	@Override
	public String quartzExprsion(){

		return "0 0 21 9 * ?";// 每月 17日0点05 启动---------------秒 分 时 日 月 周 年
	}

	@Override
	public void destory(){

	}

	@Override
	public void init( AppContext appcontext ){

		com.bj58.spat.scf.client.SCFInit.init( ConditionBuilder.DEFAULT_PATH + "/conf/scf.config" );

		List< CycleCondtion > list = new ArrayList< CycleCondtion >();

		String nowDate = DateHelper.convertDatetoString( "yyyyMM", new Date() );
		list.add( new CateCondition() );
		list.add( new PostdateCondition( nowDate + "01", nowDate + "31", true ) );
		list.add( new StateCondition() );
		list.add( new LocalCondition() );

		builder = new ConditionBuilder( list );
	}

	@Override
	public void start(){

		try{
			builder.separation( "now", 1 );
		}
		catch( Exception e ){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		new TaskTest().test();
	}

}
